import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useUserStore = defineStore('user',()=>{
  const token = ref('')
  const userInfo = ref({
    userId: '',
    userName: '',
    name: '',
    sex: '',
    studentNumber: '',
    phonenumber: '',
    major: '',
    classroom: ''
  })

  const getToken = (t)=>{
    token.value = t
  }

  const removeToken = ()=>{
    token.value = ''
    userInfo.value = {
      userId: '',
      userName: '',
      name: '',
      sex: '',
      studentNumber: '',
      phonenumber: '',
      major: '',
      classroom: ''
    }
  }

  const setUserInfo = (info) => {
    userInfo.value = info
  }

  return {
    token,
    userInfo,
    getToken,
    removeToken,
    setUserInfo
  }
},{persist: true})